package com.longma.server.controller;

import com.longma.server.entity.AddressTree;
import com.longma.server.pojo.UserResponseEntity;
import com.longma.server.service.IAddressTreeService;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.*;

import javax.validation.constraints.NotNull;
import java.util.List;


@RestController
@Validated
@RequestMapping("/api/address")
public class AddressTreeController {
    @Autowired
    private IAddressTreeService addressTreeService;

    @ApiOperation(value = "获取完整树结构")
    @GetMapping("/get")
    public UserResponseEntity<List<AddressTree>> getAddressTree(){
        return UserResponseEntity.success(addressTreeService.getAddressTree());
    }

    @ApiOperation(value = "根据id获取树结构")
    @GetMapping("/getbyid")
    public UserResponseEntity<AddressTree> getAddressTreeById(@NotNull(message = "id不能为空")  @RequestParam(name = "id") Integer id){
        return UserResponseEntity.success(addressTreeService.getAddressTreeById(id));
    }
}
